﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.Common;
using KenLib.BusinessManager;
using DataInfo;
using System.Collections.Generic;

public partial class JOINT_MstPage_JOINT : System.Web.UI.MasterPage
{
    本社情報Manager _本社情報Manager = new 本社情報Manager();
    基本情報Manager _基本情報Manager = new 基本情報Manager();
    public int year = 0;
    string strDivsName = "div_input,div_frmJ_TraineeManager,div_frmJ_TraineeList,div_frmJ_IntroCompManager,div_frmJ_IntroCompList,div_frmJ_IntroCompBasicInfo," +
        "div_frmJ_IntroCompBasicInfo1,div_frmJ_IntroCompBranchInfo,div_frmJ_IntroCompBranchInfo1,div_frmJ_IntroCompHistoryInfo,"+
        "div_frmJ_IntroCompHistoryInfo1,div_frmJ_OrgList,div_frmJ_OrgCompList,div_frmJ_OrgCompList1,"+
        "div_frmJ_OrgCompBasicInfoRef,div_frmJ_OrgCompBasicInfoRef1,div_frmJ_OrgCompBranchInfoRef,div_frmJ_OrgCompBranchInfoRef1,"+
        "div_frmJ_OrgCompHistoryInfoRef,div_frmJ_OrgCompHistoryInfoRef1,div_frmJ_AppCompBasicInfoRef,div_frmJ_AppCompBasicInfoRef1,"+
        "div_frmJ_AppCompBranchInfoRef,div_frmJ_AppCompBranchInfoRef1,div_frmJ_AppCompHistoryInfoRef,div_frmJ_AppCompHistoryInfoRef1,"+
        "div_frmJ_MCompManager,div_frmJ_MCompManager1,div_frmJ_JointCompBasicInfoRef,div_frmJ_JointCompBasicInfoRef1,div_frmJ_JointCompBranchInfoRef,div_frmJ_JointCompBranchInfoRef1,"+
        "div_frmJ_JointCompHistoryInfoRef,div_frmJ_JointCompHistoryInfoRef1,div_frmJ_EmpBasicInfo,div_frmJ_EmpBasicInfo1,"+
        "div_frmJ_TraineeListSelect,div_frmJ_TraineeListSelectCheck,div_frmJ_TraineeInterviewList,div_frmJ_InterviewTraineeListSendEmail,div_frmJ_TestResultInput" +
        ",div_frmJ_TraineeResumeBInput,div_frmJ_TraineeResumeAInput,div_frmJ_TraineeSearch,div_frmJ_CompBranchInput,div_frmJ_CompBranchHistoryInput" +
        ",div_frmJ_IntroCompBasicInput,div_frmJ_StaffAcademicInput,div_frmJ_StaffWorkedCompInput,div_frmJ_CompBasicInput,div_frmJ_CompHistoryInput,div_frmJ_CompBasicInputCheck" +
        ",div_frmJ_StaffContractTypeInput,div_frmJ_InterviewTraineeListSendEmail,frmJ_InterviewResultCheck,div_frmJ_IntroCompList,div_frmJ_StaffBasicInfoInput,div_frmJ_StaffEnterInput" +
        ",div_frmJ_StaffDegreeByCompInput,div_frmJ_StaffCareerInput,div_frmJ_StaffLangAbilityInput,div_frmJ_StaffWorkSkillInput,frmJ_StaffRewPunInput,div_frmJ_StaffRewPunInput" +
        ",div_frmJ_IntroCompBasicInputCheck,div_frmJ_InterviewResultCheck,div_frmJ_TraineeResumeOutput";

    /// <summary>
    /// Coder: Dong
    /// Noi dung: Hien thi ten va quyen dang nhap len master pager
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {

        //if (Session["frmD_Login_user"] != null && Session["frmD_Login_user"].ToString() != "")
        //{
        //    if (Session["frmD_Login_user"].ToString() == "5")
        //    {
        //        lbl_User.Text = "Administrator";
        //        lbl_User.ForeColor = System.Drawing.Color.Yellow;
        //    }
        //    else if (Session["frmD_Login_user"].ToString() == "6")
        //    {
        //        DataTable dt1 = new DataTable();
        //        DataTable dt2 = new DataTable();
        //        if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
        //        {
        //            dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
        //            dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
        //            if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
        //            {
        //                lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
        //                lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
        //                lbl_User.ForeColor = System.Drawing.Color.Yellow;
        //            }
        //            else
        //            {
        //                Response.Redirect("../frmD_Login.aspx");
        //            }
        //        }
        //    }
        //    else if (Session["frmD_Login_user"].ToString() == "7")
        //    {
        //        DataTable dt1 = new DataTable();
        //        DataTable dt2 = new DataTable();
        //        if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
        //        {
        //            dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
        //            dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
        //            if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
        //            {
        //                lbl_User.Text =ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
        //                lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
        //            }
        //            else
        //            {
        //                Response.Redirect("../frmD_Login.aspx");
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Response.Redirect("../frmD_Login.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("../frmD_Login.aspx");
        //}


        if (Session["frmD_Login_user"] != null && Session["frmD_Login_user"].ToString() != "")
        {
            if (Session["frmD_Login_user"].ToString() == "4")
            {
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "")
                {
                    DataTable dt1 = new DataTable();
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    if (dt1.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        lbl_User.Text = "";
                    }
                }
                else
                {
                    Response.Redirect("frmD_Login.aspx");
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "5")
            {
                lbl_User.Text = "Administrator";
                lbl_User.ForeColor = System.Drawing.Color.Yellow;
            }
            else if (Session["frmD_Login_user"].ToString() == "6")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                        lbl_User.ForeColor = System.Drawing.Color.Yellow;
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "7")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "8")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                        lbl_User.ForeColor = System.Drawing.Color.Yellow;
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else if (Session["frmD_Login_user"].ToString() == "9")
            {
                DataTable dt1 = new DataTable();
                DataTable dt2 = new DataTable();
                if (Session["frmD_Login_企業コード"] != null && Session["frmD_Login_企業コード"].ToString() != "" && Session["frmD_Login_人コード"] != null && Session["frmD_Login_人コード"].ToString() != "")
                {
                    dt1 = _本社情報Manager.frmD_UserLoginManager_Select企業ID_本社情報(Session["frmD_Login_企業コード"].ToString());
                    dt2 = _基本情報Manager.frmD_Login_Get社員ID(Convert.ToInt32(dt1.Rows[0]["企業ID"]), Session["frmD_Login_人コード"].ToString());
                    if (dt1.Rows.Count > 0 && dt2.Rows.Count > 0)
                    {
                        lbl_User.Text = ShowTextLength(dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString());
                        lbl_User.ToolTip = dt2.Rows[0]["姓名"].ToString() + "・" + dt1.Rows[0]["企業名"].ToString();
                    }
                    else
                    {
                        Response.Redirect("frmD_Login.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("frmD_Login.aspx");
            }
        }
        else
        {
            //Response.Redirect("frmD_Login.aspx");
            lbl_User.Text = "";
        }

        //Coder: Dong
        //Date: 2012/02/13
        //string temp = Request.UrlReferrer.ToString();
        //hpl_メインメニュー.Attributes.Add("onclick", "if(confirm('" + GetError("CF00002") + "')== false) return false;");
       
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Cut string when string too long
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ShowTextLength(string temp)
    {

        if (checkContainsUnicodeCharacter(temp))
        {
            //true tieng nhat
            if (temp.Length > 50)
            {
                temp = temp.Substring(0, 50) + "...";
            }
        }
        else
        {
            //tieng viet
            if (temp.Length > 80)
            {
                temp = temp.Substring(0, 80) + "...";
            }
        }

        return temp;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check byte string
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public bool checkContainsUnicodeCharacter(string input)
    {
        const int MaxAnsiCode = 255;
        char[] a = input.ToCharArray();
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] > MaxAnsiCode)
            {
                return true;
            }
        }
        return false;
    }
    
    public void changeTitle(string value)
    {
        lbl_titleHeader.Text = value;
    }
    public void HideLiArea(string divShowName)
    {
        string[] str = strDivsName.Split(',');
        for (int i = 0; i < str.Length; i++)
        {
            Control c = aaa.FindControl(str[i]);
            if (c != null)
                c.Visible = false;
        }
        Control c1 = aaa.FindControl("div_" + divShowName);
        if (c1 != null)
            c1.Visible = true;
        Control c2 = aaa.FindControl("div_" + divShowName + "1");
        if (c2 != null)
            c2.Visible = true;
        if (Request.CurrentExecutionFilePath.Contains("frmJ_Trainee") && !Request.CurrentExecutionFilePath.Contains("frmJ_TraineeManager.aspx"))
        {
            hpl_メインメニュー.NavigateUrl = "~/frm_MJointCompManager.aspx";
        }
        
    }
    public void ChangeMenu(string strText,string strUrl)
    {
        string[] str = strDivsName.Split(',');
        for (int i = 0; i < str.Length; i++)
        {
            Control c = aaa.FindControl(str[i]);
            if (c != null)
                c.Visible = false;
        }
        div_input.Visible = true;
        hpl_メインメニュー.Text = strText;
        hpl_メインメニュー.NavigateUrl = strUrl;
    }

    protected void lbtnLogout_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("~/frmD_Login.aspx");
    }

    // Coder: Dong
    // Date: 2012/02/13
    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            error = dt.Rows[0][2].ToString();
        }
        return error;
    }
}
